@extends('layouts.admin')

@section('title', '荣誉管理')

@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 办公 <span class="c-gray en">&gt;</span> 教师管理 <span class="c-gray en">&gt;</span> 荣誉管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="mt-20">
            <table id="listTable" class="table table-border table-bordered table-bg table-hover">
                <thead>
                <tr class="text-c">
                    <th><input type="checkbox" name="checkList"/></th>
                    <th>姓名</th>
                    <th>主要部门</th>
                    <th>主要岗位</th>
                    <th>手机</th>
                    <th>微信号</th>
                    <th>账号状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
@endsection
@section('script')
    <script>
        var $dataTable=null;
        var $MAIN={currentPage:1,StatusType:{ON_WORK:1,LOCK:2,LEAVE:3}}
        $(function(){
            $dataTable=$('#listTable').dataTable({
                "sPaginationType" : "full_numbers",
                "processing": true,
                "serverSide": true,
                "searching": false,
                "dom": '<l<\'#topPlugin\'>f>rt<ip><"clear">',
                "ajax":{
                    "url":"{{url('system/user/list')}}",
                    "type": 'post',
                    "data": function ( d ) {
                        d.name= $("#query_name").val();
                        d.teacher=1;
                        d.page=$MAIN.currentPage;
                    },
                    'dataSrc':function(result){
                        var datas=result.data;
                        if(datas){
                            for(var i=0;i<datas.length;i++){
                                datas[i].DT_RowClass='text-c';
                            }
                        }
                        return datas;
                    }
                },
                "columnDefs": [{
                    "targets": "_all",
                    "searchable":false
                },{
                    "targets": [-1,0,1,4,5],
                    "orderable":false
                }],
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return '<input type="checkbox"  name="checkList" class="checkchild"  value="' + data + '" />';
                        }
                    },
                    { "data": "name"},
                    { "data": "major_department_name"},
                    { "data": "major_station_name" },
                    { "data": "phone" },
                    { "data": "wx_no" },
                    { "data": "account_status","render": function (data, type, row, meta) {
                        if(data==$MAIN.StatusType.ON_WORK){return '<span class="label label-success radius">在职</span>';}
                        if(data==$MAIN.StatusType.LOCK){return '<span class="label label-warning radius">锁定</span>';}
                        if(data==$MAIN.StatusType.LEAVE){return '<span class="label label-danger radius">离职</span>';}
                    }},
                    { "data": "created_at" },
                    { "data": "id","class":"f-14","render": function (data, type, row, meta) {
                        return '<a title="编辑荣誉" href="javascript:;" data-id="'+data+'" data-name="'+row['name']+'" class="ml-5 editBtn" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>' ;
//                            '<a title="删除" href="javascript:;" data-id="'+data+'" class="ml-5 delBtn" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td';
                    }},
                ],
                drawCallback: function( settings ) {
                    $('input[name=checkList]')[0].checked=false;
                },
                "initComplete":function(settings, json){
                    var topPlugin='<input type="text" class="input-text radius size-M" id="query_name" style="width: 200px;" placeholder="输入姓名查询">'+
                        '&nbsp; <button type="button" class="btn btn-success radius btnSearch"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>'
                    $("#topPlugin").append(topPlugin);
                }
            });
            $dataTable.on( 'page.dt', function () {
                var info = $dataTable.api();
                $MAIN.currentPage=parseInt(info.page())+1;
            } );
        });

        $MAIN.search=function(){
            $dataTable.api().ajax.reload();
        }
        $MAIN.deleteData=function(id){
            layer.confirm('确定要删除该用户吗？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('system/user/delete')}}",
                        data:{id:id},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                $MAIN.search();
                            }else{
                                layer_error_message(data['msg']);
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        }

        $(function(){
            $(document).on("click",".btnSearch",function(){
                $MAIN.search();
            });
            $(document).on("click",".editBtn",function(){
                layer_full_show("["+$(this).data("name")+"]教师荣誉信息",'{{url('teacher/teacher/honour_edit')}}?teacher_id='+$(this).data("id"));
            });
            $(document).on("click",".delBtn",function(){
                $MAIN.deleteData($(this).data("id"));
            });
        })
    </script>
@endsection